home *** CD-ROM | disk | FTP | other *** search
- /* main.c */
-
- #include <assert.h>
-
- #include "SCSIDefines.h"
- #include "Defines.h"
- #include "Prototypes.h"
-
- MenuHandle gAppleMenu, gFileMenu, gEditMenu; /* menus */
- Boolean gDone; /* done flag */
- EventRecord gTheEvent; /* event record */
-
- void main(void)
- {
- /* set up minimum stack space */
-
- SetApplLimit(GetApplLimit() - MIN_STACK);
- assert(StackSpace() >= MIN_STACK);
-
- ToolBoxInit();
- MenuBarInit();
- Initialize();
- MainLoop();
- }
-
- void MenuBarInit()
- {
- Handle myMenuBar;
-
- myMenuBar=GetNewMBar(MENU_BAR_ID);
- SetMenuBar(myMenuBar);
-
- gAppleMenu=GetMHandle(APPLE_MENU_ID);
- AddResMenu(gAppleMenu,'DRVR');
-
- gFileMenu=GetMHandle(FILE_MENU_ID);
- gEditMenu=GetMHandle(EDIT_MENU_ID);
-
- DrawMenuBar();
- }
-
- void ToolBoxInit(void)
- {
- InitGraf(&thePort);
- InitFonts();
- FlushEvents(everyEvent, 0);
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(NULL);
- InitCursor();
- }
-
-
- void MainLoop()
- {
- char theChar; /* key character */
-
- gDone=FALSE;
- while(gDone==FALSE)
- {
-
- /* get events */
-
- WaitNextEvent(everyEvent,&gTheEvent,MIN_SLEEP,NIL_MOUSE_REGION);
-
- /* and act on it */
-
- switch (gTheEvent.what)
- {
- case mouseDown:
- HandleMouseDown();
- break;
-
- case keyDown:
- case autoKey:
- theChar=gTheEvent.message & charCodeMask;
- if ((gTheEvent.modifiers & cmdKey)!=0)
- {
- AdjustMenus();
- HandleMenuChoice(MenuKey(theChar));
- }
- break;
-
- case updateEvt:
- break;
- }
- }
- }
-
- void HandleMouseDown()
- {
- WindowPtr whichWindow;
- short thePart;
- long menuChoice,windSize;
-
- thePart=FindWindow(gTheEvent.where,&whichWindow);
- switch (thePart)
- {
- case inMenuBar:
- AdjustMenus();
- menuChoice=MenuSelect(gTheEvent.where);
- HandleMenuChoice(menuChoice);
- break;
-
- case inSysWindow:
- SystemClick(&gTheEvent,whichWindow);
- break;
- }
- }
-
- void AdjustMenus()
- {
- /* check for desk accessories */
-
- if (IsDAWindow(FrontWindow()))
- {
- EnableItem(gEditMenu,UNDO_ITEM);
- EnableItem(gEditMenu,CUT_ITEM);
- EnableItem(gEditMenu,COPY_ITEM);
- EnableItem(gEditMenu,PASTE_ITEM);
- EnableItem(gEditMenu,CLEAR_ITEM);
- }
- else
- {
- DisableItem(gEditMenu,UNDO_ITEM);
- DisableItem(gEditMenu,CUT_ITEM);
- DisableItem(gEditMenu,COPY_ITEM);
- DisableItem(gEditMenu,PASTE_ITEM);
- DisableItem(gEditMenu,CLEAR_ITEM);
- }
-
- }
-
- short IsDAWindow(whichWindow)
- WindowPtr whichWindow;
- {
- if (whichWindow==NULL) return (FALSE);
- else /* DA windows have negative windowKinds */
- return(((WindowPeek)whichWindow)->windowKind<0);
- }
-
- void HandleMenuChoice(menuChoice)
- long menuChoice;
- {
- short theMenu;
- short theItem;
-
- if (menuChoice!=0)
- {
- theMenu=HiWord(menuChoice);
- theItem=LoWord(menuChoice);
- switch (theMenu)
- {
- case APPLE_MENU_ID:
- HandleAppleChoice(theItem);
- break;
-
- case FILE_MENU_ID:
- HandleFileChoice(theItem);
- break;
-
- case EDIT_MENU_ID:
- HandleEditChoice(theItem);
- break;
- }
- HiliteMenu(0);
- }
- }
-
- void HandleAppleChoice(theItem)
- short theItem;
- {
- Str255 accName;
- short accNumber;
-
- switch (theItem)
- {
- case ABOUT_ITEM:
- NoteAlert(ABOUT_ID,NULL);
- break;
-
- default:
- GetItem(gAppleMenu,theItem,accName);
- accNumber=OpenDeskAcc(accName);
- break;
- }
- }
-
- void HandleEditChoice(theItem)
- short theItem;
- {
- SystemEdit(theItem-1);
- }
-
- void HandleFileChoice(theItem)
- short theItem;
- {
- switch (theItem)
- {
- case READ_TAPE_ITEM:
- case LIST_TAPE_ITEM:
- case WRITE_TAPE_ITEM:
- case DUMP_TAPE_ITEM:
- case DUMP_FILE_ITEM:
- DoWork(theItem);
- break;
-
- case QUIT_ITEM:
- gDone=TRUE;
- break;
- }
- }
-
-
-
-
-